import 'package:flutter/material.dart' ;
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SliderItem extends StatefulWidget {
  Widget child ;
  Widget action ;
  SliderItem({Key key , @required this.child , @required this.action}):super(key:key) ;
  @override
  _SliderItemState createState() => _SliderItemState();
}

class _SliderItemState extends State<SliderItem> with SingleTickerProviderStateMixin {
  var begin_x , begin_y , begin_time ;
  double left = 0 , right = 0 ;
  double width = 0 ;
  bool flag = false ;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.centerRight,
      children: <Widget>[
        Positioned(
          left: left ,
          right: right ,
          child: GestureDetector(
            child: Container(
              decoration: BoxDecoration(
                color: Color.fromARGB(0, 255, 255, 255) ,
              ),
              child: widget.child,
            ),
            onHorizontalDragStart: (DragStartDetails e){
              begin_x = e.localPosition.dx ;
              begin_y = e.localPosition.dy ;
              begin_time = DateTime.now().millisecondsSinceEpoch ;
            },
            onHorizontalDragUpdate: (DragUpdateDetails e){
              if(!flag && e.localPosition.dx - begin_x < 0) {
                flag = true ;
                left = - ScreenUtil().setWidth(50) ;
                right = ScreenUtil().setWidth(50) ;
                // controller.forward() ;
                setState(() {});
              }
              if(flag && e.localPosition.dx - begin_x > 0) {
                flag = false ;
                left = 0 ;
                right = 0 ;
                // controller.reverse() ;
                setState(() { });
              }
            },
          ),
        ) ,
        Visibility(
          visible: flag,
          child: widget.action ,
        ) ,
      ],
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}